﻿<div class="wrap">
    <form action="/Account/Register" method="post" role="form">
        <div class="complete-info register mt50">
            <ul class="inp-list">
                <li>
                    <label><i>*</i>手机号码</label>
                    <input type="text" class="inp" placeholder="请输入手机号码" maxlength="11" id="Phone" name="Phone" />
                    <a href="javascript:;" class="get-verify-code" id="btVerifyCode" rel="click">获取验证码</a>
                </li>
                <li>
                    <label><i>*</i>验证码</label>
                    <input type="text" class="inp" placeholder="请输入验证码" maxlength="8" id="Verify_Code" name="Verify_Code" />
                </li>
                <li>
                    <label><i>*</i>密码</label>
                    <input type="password" class="inp" placeholder="请输入密码" id="Password" name="Password" />
                </li>
                <li>
                    <label><i>*</i>确认密码</label>
                    <input type="password" class="inp" placeholder="请输入确认密码" id="ConfirmPassword" name="ConfirmPassword" />
                </li>
                <li>
                    <label><i></i></label>
                    <input type="submit" class="btn" value="注册" />
                    <input type="hidden" value="@ViewBag.ErrMsg" id="errMsg" />
                </li>
            </ul>
        </div>
        </form>
</div>
<script language="javascript">
    $(document).ready(function () {
        if ($("#errMsg").val() != "") {
            alert($("#errMsg").val());
        }

        $("#btVerifyCode").bind("click", function () {
            GetVerifyCode();
        });
    });

    function GetVerifyCode() {
        if ($("#btVerifyCode").attr('rel') == 'click') {
            var postData = {
                Phone: $("#Phone").val()
            }

            if ($("#Phone").val().length < 11) {
                alert("手机号码不正确");
                return;
            }
            var countdown = 60;
            for (i = 1; i <= countdown; i++) {
                window.setTimeout("SetShowTime(" + i + "," + countdown + ")", i * 1000);
            }

            $.ajax({
                url: "/api/AccountApi/GetVerifyCode",
                type: "POST",
                data: postData,
                success: function (data) {
                    var result = JSON.parse(data);
                    if (result.Ok == false) {
                        if (result.Message != null) {
                            alert(result.Message);
                        }
                    }
                    else {
                        alert("短信验证码已经发送")
                    }
                },
                error: function (xmlHttpRequest, textStatus, errorThrown) {
                }
            });
        }
    }

    function SetShowTime(num, t) {
        if (num == t) {
            $("#btVerifyCode").attr('rel', 'click');
            $("#btVerifyCode").html("获取验证码");
        } else {
            var showTime = t - num;
            $("#btVerifyCode").attr('rel', 'nonclick');
            $("#btVerifyCode").html("获取验证码(" + showTime + ")秒");
        }
    }
</script>